****APPENDIX TABLE C8****

cd "$main_dir/output/tables/appendix_c"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Generate relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1 yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1 yob_ln_gdppc)

fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.

//--------------------------------------------------------
//Create Table C8
//--------------------------------------------------------

//Column 1
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & age>=15 & age<=30, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c8.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
													    Survey Year FE x Survey FE, Yes, ///
													    Subcontinent FE x Cohort FE, Yes, ///
													    Age Sample, 15-30, ///
														Sample, Harmonized) keep(zwgrowth_rate_1) 

//Column 2
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & age>30 & age<=45, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c8.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													    Survey Year FE x Survey FE, Yes, ///
													    Subcontinent FE x Cohort FE, Yes, ///
													    Age Sample, 30-45, ///
														Sample, Harmonized) keep(zwgrowth_rate_1) 
														
//Column 3
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & age>45 & age<=60, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c8.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													    Survey Year FE x Survey FE, Yes, ///
													    Subcontinent FE x Cohort FE, Yes, ///
													    Age Sample, 46-60, ///
														Sample, Harmonized) keep(zwgrowth_rate_1) 														
	
//Column 4	
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & age>60 & age!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c8.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													    Survey Year FE x Survey FE, Yes, ///
													    Subcontinent FE x Cohort FE, Yes, ///
													    Age Sample, 60+, ///
														Sample, Harmonized) keep(zwgrowth_rate_1)		
